package com.sykj.huxianlong.controller;

import cn.hutool.core.util.StrUtil;
import com.sykj.huxianlong.entity.*;
import com.sykj.huxianlong.service.ILogService;
import com.sykj.huxianlong.service.ISystemService;
import com.sykj.huxianlong.service.IWithdrawalService;
import com.sykj.util.reponse.ResultBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @author zzy
 * @version 1.0
 * @date 2020/8/4 9:53
 */
@CrossOrigin
@Controller
@RequestMapping("withdr")
public class WithdrawalController {
    @Autowired
     private IWithdrawalService withdrawalService;
    @Autowired
    private ISystemService systemService;
    @Autowired
    private ILogService logService;
    /**
     * 提现列表查询
     * @param
     * @return
     */
    @RequestMapping("queryList")
    @ResponseBody
    public List<WithdrawalVo> queryList() {
        List<WithdrawalVo> vacationOrderPage = withdrawalService.queryWithdrawal();

        return vacationOrderPage;
    }


    /**
     * 提现表单
     * @param
     * @param
     * @return
     */

    @RequestMapping("toAdd")
    @ResponseBody
    public ResultBody toAdd(@RequestParam(value = "orderNo",required = false) String orderNo) {
        List<SysDict> type = systemService.querySysDictInfo(SysConstant.BUSI_TYPE);
        System.err.println(type);
        if(StrUtil.isNotBlank(orderNo)) {//编辑
            Withdrawal withdrawal = withdrawalService.queryWithdrawal(Long.valueOf(orderNo));
            System.err.println(withdrawal);
            return  new ResultBody("10091","成功");
        }
        return new ResultBody("10092","失败");


    }

    /**
     * 审批详情页
     * @param
     * @param
     * @param orderNo
     * @return
     */
    @ResponseBody
    @RequestMapping("provalDetail")
    public ResultBody provalDetail(@RequestParam("flowId") String flowId,@RequestParam("orderNo") String orderNo) {

        List<ProcessLog> processLogs = logService.queryOperLog(Long.valueOf(orderNo));
        System.err.println(processLogs);
        return new ResultBody("100101","审批成功");
    }


    /**
     * 填写提现单
     * @param withdrawal
     * @return
     */

    @PostMapping("saveOrder")
    @ResponseBody
    public ResultBody saveOrder(@RequestBody Withdrawal withdrawal) {
        withdrawalService.insertWithdrawal(withdrawal);
        return  new ResultBody("100201","成功");
    }


    /**
     * 提交提现申请
     * @return
     */
    @PostMapping("submitApply")
    @ResponseBody
    public ResultBody submitApply(@RequestParam("exid") String exid) {
        // boolean res = vacationOrderService.submitApply(Long.valueOf(vacationId));
        boolean submitApply = withdrawalService.submitApply(Long.valueOf(exid));
        if(submitApply){
            System.out.println("res=true");
            return new ResultBody("100301","提交成功");
        }else {
            System.out.println("--------------------");
            return new ResultBody("100302","提交失败");
        }
    }

    /**
     * 删除提现单
     * @param exid
     * @return
     */
    @PostMapping("delVacation")
    @ResponseBody
    public ResultBody delVacation(@RequestParam("exid") Long exid) {
        withdrawalService.delWithdrawal(exid);
        return new ResultBody("100401","成功");
    }

}
